package logic

import (
	"context"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetMessageListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetMessageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMessageListLogic {
	return &GetMessageListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 获取消息列表
func (l *GetMessageListLogic) GetMessageList(in *user.GetMessageListReq) (*user.GetMessageListResp, error) {
	messageList, total, err := dao.GetMessageList(in.UserId, int64(in.Page), int64(in.PageSize)) // 获取消息列表
	if err != nil {
		return nil, err
	}
	return &user.GetMessageListResp{
		Messages: messageList,
		Total:    int32(total),
	}, nil
}
